//
//  XLMainViewController.swift
//  XLWeiBo
//
//  Created by 李晓龙 on 16/9/19.
//  Copyright © 2016年 lixiaolong. All rights reserved.
//

import UIKit

class XLMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //使用KVC方式给OC中的类设置只读属性
        let xlTaBar = XLTabBar()
        
        //设置代理对象
        xlTaBar.xlDelegate = self
        
        xlTaBar.composeButtonClosure = { [weak self] in
            print("闭包调用过来的")
            
        }
        
        setValue(xlTaBar, forKey: "tabBar")
        
        
        //添加子视图控制器
        addChildViewController(childController: XLHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(childController: XLMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(childController: XLDiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(childController: XLProfileTableViewController(), title: "我的", imageName: "tabbar_profile")
        
        
    }

   
    //添加子视图控制器的方法重载
    func addChildViewController(childController: UIViewController,title: String, imageName: String) {
        
        //设置tabbarItem 的图片和文字
        childController.tabBarItem.image = UIImage(named: imageName)
        //修改图片的渲染方式
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.withRenderingMode(.alwaysOriginal)
        //设置选中文字的颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orange], for: .normal)
        //设置文字大小
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14)], for: .normal)
        
        //合并成一句代码显示
        childController.title = title
        //创建导航视图控制器
        let nav = XLNavigationVC(rootViewController: childController)
        
        //添加到子视图控制器
        addChildViewController(nav)
        
        
    }
    

    
    
    
}

    //实现代理方法
extension XLMainViewController: XLTabBarDelegate {
    
    func didSelectedComposeButton() {
         print("代理调用过来的")
    }
    
}



